/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 87111
 * Date: 2025-11-12
 * Time: 18:24
 */
public class Demo2 {
    public static void main(String[] args) throws InterruptedException {
        Object locker1 = new Object();
        Object locker2 = new Object();
        Object locker3 = new Object();

        Thread c = new Thread(() -> {
            try {
                synchronized (locker1) {
                    locker1.wait();
                }
                System.out.println("c");
                synchronized (locker2) {
                    locker2.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread b = new Thread(() -> {
            try {
                synchronized (locker2) {
                    locker2.wait();
                }
                System.out.println("b");
                synchronized (locker3) {
                    locker3.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        Thread a = new Thread(() -> {
            try {
                synchronized (locker3) {
                    locker3.wait();
                }
                System.out.println("a");
                synchronized (locker1) {
                    locker1.notify();
                }
            } catch (InterruptedException e) {
                throw new RuntimeException(e);
            }
        });
        c.start();
        b.start();
        a.start();
        Thread.sleep(1000);
        synchronized (locker1) {
            locker1.notify();
        }
    }
}
